﻿using System;
using MathNet.Numerics.LinearAlgebra;

namespace GridRayTracer
{
  [Serializable]
  public abstract class SceneObject
  {   
    public SceneObject()
    {
      Rotation = Matrix.Identity(3, 3);
      Translation = Vector.Zeros(3);
      Surface = new Surface();
    }
    
    /// <summary>
    /// Performs hit test.
    /// </summary>
    /// <param name="ray">Ray to intersect.</param>
    /// <returns>
    /// Hit information, null if there is no intersection.
    /// </returns>
    public abstract HitResult HitTest(Ray ray);        
		
	double[,] rotation = new double[3, 3];

    public Matrix Rotation
    {
      get { return Matrix.Create(rotation); }
      set 
	  { 
		rotation = value.CopyToArray(); 
		RotationInverted = value.Inverse();
	  }
    }
    
    double[,] rotationInverted = new double[3, 3];
    
    public Matrix RotationInverted 
    {
      get { return Matrix.Create(rotationInverted); }
      set { rotationInverted = value.CopyToArray(); }
    }

    public Vector Translation
    {
      get;
      set;
    }
    
    public Surface Surface
    {
      get;
      set;
    }
  }
}
